// let cp = require('child_process');
import cp from 'child_process'

const execGetSec = (pathFile) => {
    const cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 ${pathFile}`
    console.log('当前指令:', cmd)
    cp.exec(cmd, (err, stdout, errout) => {
        if (!err) {
            console.log('结果:', stdout)
        }
    })
}

const execJpg = (pathFile, saveFilePath) => {
    const cmd = `ffmpeg -i ${pathFile} -y -f image2 -ss 2 -frames 1 ${saveFilePath}`
    console.log('当前指令:', cmd)
    cp.exec(cmd, (err, stdout, errout) => {
        if (!err) {
            console.log(`${saveFilePath} success...`)
        }
    })
}

// const path = "F:\\codes\\projs\\bilibili\\bili-web\\public\\videos\\1.mp4"
// const imgpath = "F:\\codes\\projs\\bilibili\\bili-web\\public\\videos\\cover.jpg"
const path = "..\\..\\public\\videos\\1.mp4"
const imgpath = "..\\..\\public\\videos\\cover.jpg"

execGetSec(path);
execJpg(path, imgpath);